﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using shenghua.Basics.ShippingTemplates;
using shenghua.Basics.ShippingTemplateSetting.Dto;
using shenghua.Commodity.Commodities.Dto;
using shenghua.Marketing.Coupons.Dto;
using shenghua.Member.Coupons;
using shenghua.Order.Orders.Median;

namespace shenghua.Order.Orders.Dto
{
    public class OrderCoreDto
    {
        public bool CanSubmit { get; set; }
        public List<string> ErrorMessages { get; set; }

        public double Freight { get; set; }
        public double TotalAmount { get; set; }
        public CommodityCollectionDto CommodityCollection { get; set; }
        /// <summary>
        /// 可以使用的优惠券
        /// </summary>
        public List<MemberCouponDto> CanUsedCoupons { get; set; }

        /// <summary>
        /// 可以使用的运费模板
        /// </summary>
        public List<ShippingTemplateDto> CanUsedShippingTemplates { get; set; }

        public OrderCoreDto(OrderCore orderCore, List<MemberCoupon> canUsedCoupons, List<ShippingTemplate> canUsedShippingTemplates = null)
        {
            CanSubmit = orderCore.CanSubmit;
            ErrorMessages = orderCore.ErrorMessages;
            Freight = orderCore.Freight;
            TotalAmount = orderCore.TotalAmount;
            CommodityCollection = new CommodityCollectionDto(orderCore.CommodityCollection);
            CanUsedCoupons = canUsedCoupons.Select(r => new MemberCouponDto(r)).ToList();
            if(canUsedShippingTemplates != null)
            {
                CanUsedShippingTemplates = canUsedShippingTemplates.Select(r => new ShippingTemplateDto(r)).ToList();
            }else
            {
                CanUsedShippingTemplates = new List<ShippingTemplateDto>();
            }
        }
    }
}
